package com.yue.serializable;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * Created by qiuyang on 11/04/2017.
 */
public class SimpleSerializabel {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        File file = new File("person.out");

        ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream(file));
        Person person = new Person("Json", 101, Gender.MALE);
        oout.writeObject(person);
        oout.close();
        System.out.println("-------------");

        ObjectInputStream oin = new ObjectInputStream(new FileInputStream(file));
        Object newPerson = oin.readObject();
        oin.close();
        System.out.println(newPerson);
        System.out.println("------------------");

        Person person1 = (Person) newPerson;
        System.out.println(person1);
    }
}
